package binary_search;

public class minNumberInRotateArray_niuke {
    public static void main(String[] args) {
        int[] s = new int[] {1,0,1,1,1};
        int r = minNumberInRotateArray(s);
        System.out.println(r);
    }
    public static int minNumberInRotateArray (int[] nums) {
        // write code here
        //注意： 有坑点1 0 1 1 1
        int left = 0;
        int right = nums.length-1;
        int mid = 0;
        int tag = nums[right];


        while(left < right) {
            if(nums[left] < tag){//1
                return nums[left];
            }
            mid = left + (right - left)/2;
            if(nums[mid] > tag){
                left = mid+1;
            }else if(nums[mid] < tag){
                right = mid;
            }else {
                left++;//1    1和2两处巧妙避免了offer书上说的坑点（1 0 1 1 1）
            }
        }
        return nums[left];
    }
}
